home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS26.ADF / ShowPt / safeclose.c < prev    next >
C/C++ Source or Header  |  1989-01-26  |  2KB  |  54 lines

  1. /* CloseWindowSafely()
  2. *       This module should be used whenever you are sharing an IDCMP
  3. * message port with more than one window.  Rather than calling CloseWindow(),
  4. * you should use CloseWindowSafely().  This will keep Intuition from
  5. * Guru Meditation, and thus is considered a good thing.  You should still
  6. * use CloseWindow for the very last window you close.
  7. *       The reason this is needed, is because Intuition will re-claim
  8. * any outstanding messages for a window when the window is closed. But...
  9. * it can't take them out of your message port. Thus, you will receive
  10. * invalid messages and bad things will happen.  Very bad things.
  11. *       This code is a slightly condensed version of the same routine
  12. * written by Neil Katin of Amiga for the April '86 Commodore Developers
  13. * Newsletter, Amiga Mail (tm).
  14. */
  15.  
  16. /*
  17. #include <exec/types.h>
  18. #include <exec/nodes.h>
  19. #include <exec/lists.h>
  20. #include <exec/ports.h>
  21. #include <intuition/intuition.h>
  22. #include <functions.h>
  23. */
  24. #include "standard.h"
  25.  
  26. void CloseWindowSafely( p_wind )
  27.    struct Window   *p_wind;
  28.    {
  29.    register struct IntuiMessage    *msg;
  30.    register struct IntuiMessage    *succ;
  31.    register struct Window          *win = p_wind;
  32.    register struct MsgPort         *mp = (struct MsgPort *)win->UserPort;
  33.  
  34.    Forbid();
  35.  
  36.    msg = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  37.  
  38.    while ( succ=(struct IntuiMessage *)msg->ExecMessage.mn_Node.ln_Succ )
  39.       {
  40.       if ( msg->IDCMPWindow == win )
  41.          {
  42.          Remove ( msg );
  43.          ReplyMsg( msg );
  44.          }
  45.       msg = succ;
  46.       }
  47.    win->UserPort = NULL;
  48.    ModifyIDCMP( win, 0L );
  49.    Permit();
  50.    CloseWindow( win );
  51.    }
  52.  
  53.  
  54.